<?php
	require_once("../classes/Announcement.php");
	require_once("../classes/User.php");
	
	session_start();
	
	$user = $_SESSION["user"];
	
	$announcement = new Announcement();
	
	if(isset($_POST["id"])){
		$id = $_POST["id"];
	}else{
		$id = 0;
	}
	$announcement->setValues($id, $user->getId(), $_POST["title"], $_POST["description"], $_POST["location"], $_POST["category"], $_POST["salary"]);
	
	$state = $announcement->save();
	
	if($state == 2){
		$_SESSION["msg"] = "Dados Gravados.";
		header("Location: ../createAnnouncement.php");
	}else{
		$_SESSION["msg"] = "Dados Alterados.";
		header("Location: ../changeAnnouncement.php");
	}
?>